package util

import (
	"fmt"
)

var TableNotFound = fmt.Errorf("TableNotFound")
var KeyNotFound = fmt.Errorf("KeyNotFound")
var ParseArgsErr = fmt.Errorf("ParseArgsError")
var RequestArgsErr = fmt.Errorf("RequestArgsError")
var DataFormatErr = fmt.Errorf("DataFormatError")
var FileNotExit = fmt.Errorf("FileNotExit")

func ErrorHandler(name string, err error, handle func() error) {
	for err != nil {
		input := 0
		fmt.Printf("\nFail to %s: %v\n", name, err)
		fmt.Print("To try again, press '1'. To exit forcibly, press '2'.(1/2): ")
		fmt.Scanf("%d", &input)
		if input == 2 {
			break
		} else {
			err = handle()
		}
	}
}
